package com.jDesireShop.datasource.mongoDB;

import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;
import com.mongodb.DB;
import com.mongodb.Mongo;

public class MorphiaBean extends Morphia {

	private Mongo mongo = null;

	private String dbName = null;

	private int isMongo;

	public MorphiaBean() {
		super();
	}

	public void setMapPackage(String packageName) {
		super.mapPackage(packageName, true);
	}

	public void setMongo(Mongo mongo) {
		this.mongo = mongo;
	}

	public void setDbName(String dbName) {
		this.dbName = dbName;
	}

	public Mongo getMongo() {
		return mongo;
	}

	public String getDbName() {
		return dbName;
	}

	public Datastore getDataStore() {
		if (this.mongo == null || this.dbName == null) {
			return null;
		}
		// String city = SpObserver.getCity();
		// if(city!=null && !city.equals(""))
		dbName = "test";
		return createDatastore(mongo, dbName);
	}

	public DB getDB() {
		if (dbName == null || dbName.trim().equalsIgnoreCase("")) {
			return null;
		}
//		String city = SpObserver.getCity();
//		if (city != null && !city.equals(""))
			dbName = "test";
		return mongo.getDB(dbName);
	}

	public int getIsMongo() {
		return isMongo;
	}

	public void setIsMongo(int isMongo) {
		this.isMongo = isMongo;
	}

}
